package hanjia;

import java.util.HashMap;
import java.util.Set;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/10-下午3:36
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode454 {

    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        HashMap<Integer, Integer> result1 = new HashMap<>();
        HashMap<Integer, Integer> result2 = new HashMap<>();
        int result = 0;
        for (int i : nums1) {
            for (int j : nums2) {
                int sum = i + j;
                result1.put(sum, result1.getOrDefault(sum, 0) + 1);
            }
        }

        for (int i : nums3) {
            for (int j : nums4) {
                int sum = i + j;
                result2.put(sum, result2.getOrDefault(sum, 0) + 1);
            }
        }
        Set<Integer> key1 = result1.keySet();
        for (int i : key1) {
            if (result2.containsKey(-i)) {
                result += result1.get(i) * result2.get(-i);
            }
        }


        return result;

    }
}
